package com.hxkj.controller;

import com.hxkj.domain.po.WebsiteAddr;
import com.hxkj.service.WebsiteAddrService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 *  url规则配置
 * <p>
 * Created by yaosy on 2018年8月7日14:28:08
 */
@RestController
@RequestMapping("/website")
public class WebsiteAddrController {


    @Autowired
    private WebsiteAddrService websiteAddrService;

    /**
     * 获取多条规则配置 带分页
     */
    @RequestMapping(value = "/getpages",consumes  ="application/json;charset=UTF-8",method = RequestMethod.POST)
    public Callable<ResultPageStruct<WebsiteAddr>> getPages(@RequestBody ParameterDataStruct<WebsiteAddr> parameterDataStruct) {
        return ()-> ResultStructUtils.buildResultPageStruct(websiteAddrService.getPages(parameterDataStruct.getData() == null ? new WebsiteAddr() : parameterDataStruct.getData() ,parameterDataStruct.getPageTo()));
    }


    /**
     * 获取多条规则配置 不带分页
     */
    @RequestMapping(value = "/getlist",consumes  ="application/json;charset=UTF-8",method = RequestMethod.POST)
    public Callable<List<WebsiteAddr>> getList(@RequestBody WebsiteAddr websiteAddr) {
        return ()-> websiteAddrService.getList(websiteAddr == null ? new WebsiteAddr() : websiteAddr);
    }


    /**
     * 获取单条配置信息
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST,consumes = "application/json;charset=UTF-8")
    public ResultDataStruct<WebsiteAddr> get(@RequestBody WebsiteAddr websiteAddr) throws Exception{
        return websiteAddrService.get(websiteAddr);
    }

    /**
     * 修改单条配置信息
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST,consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct modifyWebsite(@RequestBody WebsiteAddr websiteAddr) throws Exception{
        return websiteAddrService.modifyWebsite(websiteAddr);
    }

    /**
     * 删除配置信息(可删除多条)
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST,consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct removeWebsite(@RequestBody WebsiteAddr websiteAddr) throws Exception{
        return websiteAddrService.removeWebsite(websiteAddr);
    }

    /**
     * 增加配置信息
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST,consumes = "application/json;charset=UTF-8")
    public ResultMessageStruct saveWebsite(@RequestBody WebsiteAddr websiteAddr) throws Exception{
        return websiteAddrService.saveWebsite(websiteAddr);
    }
}
